Skip to content

Conversation

@jonkoops
Copy link
Collaborator

What kind of change does this PR introduce?

  • Bug Fix
  • Feature
  • Refactoring
  • Style
  • Build
  • Chore
  • Documentation
  • CI

Did you add tests for your changes?

  • Yes, my code is well tested
  • Not relevant

If relevant, did you update the documentation?

  • Yes, I've updated the documentation
  • Not relevant

Summary
This converts the package into pure ESM. This means that the code is no longer distributed as anything than standard JavaScript, avoiding dual packaging hazard in the process.

This also benefits modern bundlers such as Vite, which can do more extensive optimizations on pure packages.

Does this PR introduce a breaking change?
Yes, this raises the minimum required version of Node.js to version 14. Since Node.js 12 is EOL this should not be an issue. This also drop support for all module systems beside ECMAScript.

@@ -1,17 +0,0 @@
coverage
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed this file as the files field in the package is enough for NPM to determine which files should be included. To see this in action run npm pack --dry-run in the root directory.


### CDN
For CDN, you can use [unpkg](https://unpkg.com):
If you need a CDN, you can use [Skypack](https://www.skypack.dev/view/file-selector):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skypack is an optimized CDN for serving NPM packages that use the ECMAScript module system. This allows them to be imported in scripts as outlined below, no globals needed!

```
**NOTE** The above is experimental and subject to change.

### CommonJS
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since CommonJS is no longer supported I have removed this section.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When has this happened? And what will happen to clients that still want to use this lib but have not updated to modern JS?

@@ -0,0 +1,21 @@
import type { InitialOptionsTsJest } from 'ts-jest';
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Jest configuration is now written in TypeScript as well!

"main": "./lib/index.js",
"exports": "./lib/index.js",
"types": "./lib/index.d.ts",
"sideEffects": false,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows tools like WebPack to do more advanced tree shaking on the package.

"test": "jest --watch"
},
"dependencies": {
"tslib": "^2.4.0"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're compiling to modern JavaScript we no longer need the shims from tslib.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So how about non-modern js?

"engines": {
"node": ">=14.16"
},
"devDependencies": {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I managed to remove quite a bit of dependencies as we are now only using TypeScript to compile things.

@@ -1,24 +1,14 @@
{
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've simplified the TypeScript configuration a bit by putting only the essential configuration here. Configurations for specific tasks such as the build, linting and testing all live in their own configs that extend from the root config.

]
}
},
"no-implicit-dependencies": false
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this rule detects the dependencies in the tests as 'non-dev' dependencies this yields some false positives. Since TSLint is deprecated and needs to replaced I have opted to disable this for now.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comment somewhere to do that then.

@jonkoops
Copy link
Collaborator Author

@rolandjitsu any particular reason the PR was closed?

@rolandjitsu
Copy link
Collaborator

Sorry, that was unintentional. The intent was to close the dependapot ones. Re-opening.

@rolandjitsu rolandjitsu reopened this Feb 19, 2024
Copy link
Collaborator

@rolandjitsu rolandjitsu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonkoops I've left a few comments. Mainly around backwards compat or support for older clients and build systems.

]
}
},
"no-implicit-dependencies": false
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comment somewhere to do that then.

```
**NOTE** The above is experimental and subject to change.

### CommonJS
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When has this happened? And what will happen to clients that still want to use this lib but have not updated to modern JS?

For CDN, you can use [unpkg](https://unpkg.com):
If you need a CDN, you can use [Skypack](https://www.skypack.dev/view/file-selector):
```html
<script type="module">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably worth mentioning https://caniuse.com/es6-module.

"typings": "./dist/index.d.ts",
"type": "module",
"main": "./lib/index.js",
"exports": "./lib/index.js",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So to understand, the module, es2015 and typings have been deprecated and no longer in use by other build systems?

"typings": "./dist/index.d.ts",
"type": "module",
"main": "./lib/index.js",
"exports": "./lib/index.js",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My only concern, as mentioned previously, is that clients/builders that are not modern will stop working post this change.

"test": "jest --watch"
},
"dependencies": {
"tslib": "^2.4.0"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So how about non-modern js?

@jonkoops
Copy link
Collaborator Author

@rolandjitsu I think I will split out this PR into a couple of smaller more reviewable ones. It's also been a while since this PR was created, so I'd like to re-evaluate the choices made here.

@jonkoops
Copy link
Collaborator Author

jonkoops commented Mar 2, 2024

Marking this as a draft to get back to it later when the other work has landed.

@jonkoops jonkoops marked this pull request as draft March 2, 2024 17:54
@rolandjitsu
Copy link
Collaborator

@jonkoops thanks for doing that. I appreciate your effort and sorry for the delayed reply. I'm reviewing the other PRs now.

@jonkoops
Copy link
Collaborator Author

jonkoops commented Oct 6, 2024

I am going to split this PR into some separate ones to make things easier to review. It's also been a while since I touched this PR, so I need to get back in the changes and perhaps do some things differently.

@jonkoops
Copy link
Collaborator Author

Closing this in favor of #96.

@jonkoops jonkoops closed this Oct 28, 2024
@jonkoops jonkoops deleted the esm branch October 28, 2024 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants